﻿/* 
    Copyright (c) 2011 Microsoft Corporation.  All rights reserved.
    Use of this sample source code is subject to the terms of the Microsoft license 
    agreement under which you licensed this sample source code and is provided AS-IS.
    If you did not accept the terms of the license agreement, you are not authorized 
    to use this sample source code.  For the terms of the license, please see the 
    license agreement between you and Microsoft.
  
    To see all Code Samples for Windows Phone, visit http://go.microsoft.com/fwlink/?LinkID=219604 
  
*/
using System;
using System.ComponentModel;
using System.Data.Linq;
using System.Data.Linq.Mapping;

namespace ProtoImaginer.Models
{

    public class ProtoDataContext : DataContext
    {
        // Pass the connection string to the base class.
        public ProtoDataContext(string connectionString)
            : base(connectionString)
        { }

        // Specify a table for the Projects.
        public Table<ProjectTable> Projects;

        // Specify a table for the Pages.
        public Table<PageTable> Pages;
    }

    [Table]
    public class ProjectTable : INotifyPropertyChanged, INotifyPropertyChanging
    {

        public ProjectTable(Guid ProjectId, int ProjectAuthor, string ProjectName, int ProjectStatus,
            string ProjectDescription, string ProjectKeyword, DateTime ProjectCreateDate, DateTime ProjectLastModifiedDate)
        {
            this.ProjectId = ProjectId;
            this.ProjectAuthor = ProjectAuthor;
            this.ProjectName = ProjectName;
            this.ProjectStatus = ProjectStatus;
            this.ProjectDescription = ProjectDescription;
            this.ProjectKeyword = ProjectKeyword;
            this.ProjectCreateDate = ProjectCreateDate;
            this.ProjectLastModifiedDate = ProjectLastModifiedDate;
        }

        // Define ID: private field, public property, and database column.

        [Column(IsPrimaryKey = true, IsDbGenerated = true, DbType = "INT NOT NULL Identity", CanBeNull = false, AutoSync = AutoSync.OnInsert)]
        public Guid ProjectId
        {
            get;
            set;
        }

        // Define item name: private field, public property, and database column.

        [Column]
        public string ProjectName
        {

            get;
            set;
        }

        //Define the description

        [Column]
        public string ProjectDescription
        {

            get;
            set;
        }

        //Define the keywords

        [Column]
        public string ProjectKeyword
        {

            get;
            set;
        }

        //Define the Author

        [Column]
        public int ProjectAuthor
        {

            get;
            set;
        }

        //Define the Project CreateDate

        [Column]
        public DateTime ProjectCreateDate
        {

            get;
            set;
        }

        //Define the Project LastModifiedDate

        [Column]
        public DateTime ProjectLastModifiedDate
        {

            get;
            set;
        }

        //Define the project status

        [Column]
        public int ProjectStatus
        {

            get;
            set;
        }

        // Version column aids update performance.
        [Column(IsVersion = true)]
        private Binary _version;

        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;

        // Used to notify that a property changed
        private void NotifyPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        #endregion

        #region INotifyPropertyChanging Members

        public event PropertyChangingEventHandler PropertyChanging;

        // Used to notify that a property is about to change
        private void NotifyPropertyChanging(string propertyName)
        {
            if (PropertyChanging != null)
            {
                PropertyChanging(this, new PropertyChangingEventArgs(propertyName));
            }
        }

        #endregion
    }


    [Table]
    public class PageTable : INotifyPropertyChanged, INotifyPropertyChanging
    {

        public PageTable(Guid PageId, string PageTitle, int PageAuthor, Guid PageProjectId,
            DateTime PageCreateDate, DateTime PageLastModifiedDate, int PageStatus)
        {
            this.PageId = PageId;
            this.PageTitle = PageTitle;
            this.PageAuthor = PageAuthor;
            this.PageStatus = PageStatus;
            this.PageCreateDate = PageCreateDate;
            this.PageLastModifiedDate = PageLastModifiedDate;
        }

        // Define ID: private field, public property, and database column.

        [Column(IsPrimaryKey = true, DbType = "INT NOT NULL IDENTITY", IsDbGenerated = true, CanBeNull = false)]
        public Guid PageId
        {

            get;
            set;
        }

        // Define category name: private field, public property, and database column.

        [Column]
        public string PageTitle
        {

            get;
            set;
        }

        //Define the Author

        [Column]
        public int PageAuthor
        {

            get;
            set;
        }


        [Column]
        public Guid PageProjectId
        {

            get;
            set;
        }

        //Define the Project CreateDate

        [Column]
        public DateTime PageCreateDate
        {

            get;
            set;
        }

        //Define the Project LastModifiedDate

        [Column]
        public DateTime PageLastModifiedDate
        {

            get;
            set;
        }

        //Define the project status

        [Column]
        public int PageStatus
        {

            get;
            set;
        }


        // Version column aids update performance.
        [Column(IsVersion = true)]
        private Binary _version;

        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;

        // Used to notify that a property changed
        private void NotifyPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        #endregion

        #region INotifyPropertyChanging Members

        public event PropertyChangingEventHandler PropertyChanging;

        // Used to notify that a property is about to change
        private void NotifyPropertyChanging(string propertyName)
        {
            if (PropertyChanging != null)
            {
                PropertyChanging(this, new PropertyChangingEventArgs(propertyName));
            }
        }

        #endregion
    }


}
